﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jayden.Dll.Core.Persistence.Data.SQLite;
using Jayden.Dll.Core;
using Jayden.Dll.Core.Persistence;
using Jayden.Dll.Core.Persistence.Models;
using Jayden.Dll.Core.Persistence.Data;
using System.Data.Common;

namespace Jayden.Dll.Cards.Poker
{
	public class SQLiteTexasHoldemPlayerStatisticsDataAccess : SQLiteDataAccess<TexasHoldemPlayerStatistics>, TexasHoldemPlayerStatisticsDataAccess
	{
		public SQLiteTexasHoldemPlayerStatisticsDataAccess(Configuration config, UnitOfWork uow, Entity entity) : base(config, uow, entity) { }

		public List<TexasHoldemPlayerStatistics> ReadAll()
		{
			string selectCommandText = Helper.GenerateSelect(null, Entity.Table.TableName, null, null, null, null, null);
			using (DbCommandProxy selectCommand = CreateCommand(selectCommandText))
			{
				using (DbDataReader reader = selectCommand.Command.ExecuteReader())
				{
					List<TexasHoldemPlayerStatistics> statistics = new List<TexasHoldemPlayerStatistics>(EnumerateFromReader(reader));
					return statistics;
				}
			}
		}

		public TexasHoldemPlayerStatistics Read(string providerName, string playerName, ulong limit, string currency)
		{
			string selectCommandText = Helper.GenerateSelect(Entity, Entity["ProviderName"], Entity["PlayerName"], Entity["BigBlind"], Entity["Currency"]);
			using (DbCommandProxy selectCommand = CreateCommand(selectCommandText))
			{
				CreateParameter(selectCommand, "ProviderName", providerName);
				CreateParameter(selectCommand, "PlayerName", playerName);
				CreateParameter(selectCommand, "BigBlind", limit);
				CreateParameter(selectCommand, "Currency", currency);
				using (DbDataReader reader = selectCommand.Command.ExecuteReader())
				{
					TexasHoldemPlayerStatistics statistics = CreateFromReader(reader);
					return statistics;
				}
			}
		}
	}
}
